home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: netcom.com!jodell
- From: jodell@netcom.com (Jake Odell)
- Subject: Re: Help !!!!! on 'strstr"
- Message-ID: <jodellDo77pn.Kuw@netcom.com>
- Organization: NETCOM On-line Communication Services (408 261-4700 guest)
- X-Newsreader: TIN [version 1.2 PL1]
- References: <314703FF.4045@msmail.st.stems.com> <jodellDo7097.Bto@netcom.com>
- Date: Wed, 13 Mar 1996 09:00:59 GMT
- Sender: jodell@netcom20.netcom.com
-
- Jake Odell (jodell@netcom.com) posted:
- # kim hai (Kim_Hai.Ng@msmail.st.stems.com) posted:
- # # Help !!!!!
-
- # # Problem :
- # # I need to locate a string within another string, and the process
- # # must be case insensitive. As far as I know, strstr() only locates the
- # # exact match and is case sensitive.
- # # Does anyone konw of any functions that could allow me to locate
- # # substrings and is case insensitive ?
-
- # # Eg.
- # # case 1:
- # # string1 = "abc"
- # # string2 = "abcdef"
- # # case 2:
- # # string2 = "Abcdef"
- # # case 3:
- # # string3 = "aBcdef"
- # # case 4:
- # # string4 = "abCdef"
- # # ...
- # # ..
- # # .
-
- # Here is istrstr() that came out of
- # a similar thread a while back:
-
- # /*
- # * istrstr.c
- # */
- # #if defined(DEBUG)
- # # include <stdio.h>
- # #endif
- # #include <ctype.h>
-
- # typedef unsigned char uchar;
-
- # char *istrstr(s1, s2) char *s1; char *s2;
- # { char *p, *ret;
- # int len1, len2, matches;
- # int c1, c2;
-
- # for (len1 = 0; s1[len1]); len1++);
- # for (len2 = 0; s2[len2]); len2++);
-
- sigh.. some typoes: ^-- remove these two rparens
-
- # if (len2 > len1) return NULL;
- # p = ret = s1;
-
- and an omission:
-
- matches = 0; /* needed for DEBUG */
-
- # while (*p)
- # {
- # #if defined(DEBUG)
- # c1 = *p;
- # c2 = s2[matches];
- # printf("%c/%02x %c/%02x", c1, c1, c2, c2);
- # #endif
- # if ((c1 = toupper((uchar) *p++))
- # == (c2 = toupper((uchar) s2[matches++])))
- # {
- # #if defined(DEBUG)
- # printf("\n");
- # #endif
- # if (matches == len2) return ret;
- # continue;
- # }
- # ret = p;
- # if (matches = (c1 == toupper((uchar) *s2)) ? 1 : 0) ret--;
- # #if defined(DEBUG)
- # printf("%s\n", matches ? " <-rewind s2 match" : "");
- # #endif
- # }
- # return s2[matches] ? NULL : ret;
- # }
-
- and you'll need a definition for NULL.
-
- --
- jake@pantheon.us.com jodell@netcom.com
-